package org.musync;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;

/**
 * Dynafilter is a way of dynamically filtering files to find media files that are supported
 * by the musync plugins.
 * @author james
 *
 */
public class DynaFilter implements FileFilter {

	ArrayList<String> extensions;
	
	/**
	 * Constructor used to make a new dynafilter
	 */
	public DynaFilter(){
		extensions = new ArrayList<String>();
	}
	
	/**
	 * Function used to register handlers for a specific file extension.
	 * @param extension
	 */
	public void registerExtension(String ext){
		extensions.add(ext);
	}
	

	@Override
	public boolean accept(File arg0) {
		
		
		for(String ext : extensions){
			
			String filename = arg0.getAbsolutePath();
			
			if(filename.endsWith(ext))
				return true;
		}
		
		return false;
	}

}
